package com.realgodo.site.service.dic;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.hibernate.DefaultEntityManager;

import com.realgodo.site.entity.common.Attachment;
import com.realgodo.site.entity.dic.Face;

@Service
@Transactional
public class FaceManager extends DefaultEntityManager<Face, Long> {
	@Autowired
	protected SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	public List<Face> getAll(){
		Criteria c = sessionFactory.getCurrentSession().createCriteria(Face.class);
		c.add(Restrictions.eq("isDelete", Face.NOT_DELETED));
		c.addOrder(Order.asc("id"));
		List faceList=c.list();
		if(faceList==null||faceList.size()==0){
			for(int i=1;i<21;i++){
				Face face=new Face();
				face.setIsDelete(Attachment.NOT_DELETED);
				face.setName(i+".jpg");
				face.setPath("userfiles/image/face/3d/");
				face.setType(3);
				this.save(face);
			}
			for(int i=1;i<16;i++){
				Face face=new Face();
				face.setIsDelete(Attachment.NOT_DELETED);
				face.setName(i+".jpg");
				face.setPath("userfiles/image/face/2d/");
				face.setType(2);
				this.save(face);
			}
			for(int i=1;i<21;i++){
				Face face=new Face();
				face.setIsDelete(Attachment.NOT_DELETED);
				face.setName(i+".jpg");
				face.setPath("userfiles/image/face/1d/");
				face.setType(1);
				this.save(face);
			}
		}
		faceList=c.list();
		faceList=faceList==null?new ArrayList<Face>():faceList;
		return faceList;
	}

}
